
using QdbUnit.Extensions.Fixtures;
using QdbUnit.Extensions.Util;
using Qdb;
using Qdb.Config;

namespace QdbUnit.Extensions.Fixtures
{
	public abstract class AbstractFileBasedQdbFixture : AbstractSoloQdbFixture
	{
		private readonly Sharpen.IO.File _databaseFile;

		public AbstractFileBasedQdbFixture()
		{
			string fileName = FileName();
			_databaseFile = new Sharpen.IO.File(CrossPlatformServices.DatabasePath(fileName));
		}

		protected abstract string FileName();

		protected override IObjectContainer CreateDatabase(IConfiguration config)
		{
			return QdbFactory.OpenFile(config, GetAbsolutePath());
		}

		public virtual string GetAbsolutePath()
		{
			return _databaseFile.GetAbsolutePath();
		}

		/// <exception cref="System.Exception"></exception>
		public override void Defragment()
		{
			Defragment(GetAbsolutePath());
		}

		protected override void DoClean()
		{
			_databaseFile.Delete();
		}
	}
}
